import { ApolloClient, ApolloCache, InMemoryCache } from "@apollo/client";

import { setContext } from "@/ApolloClient/apollo.ts"

import createUploadLink from "apollo-upload-client/createUploadLink.mjs";

const authLink = setContext((_, { headers }) => {
    return {
        headers: {
            ...headers,
            "X-PASS": localStorage.getItem("password"),
            'Apollo-Require-Preflight': 'true'
        },
    };
});

export default new ApolloClient({
    link: authLink.concat(createUploadLink({ uri: "/api/ql" })),
    cache: new InMemoryCache(),
    defaultOptions: {
        watchQuery: { fetchPolicy: "no-cache", errorPolicy: "ignore" },
        query: { fetchPolicy: "no-cache", errorPolicy: "all" },
    },
});